#ifndef STDAFX_H
#define STDAFX_H

#include <QMainWindow>
#include <QMessageBox>
#include <QMouseEvent>
#include <QTimer>
#include <QTime>
#include <QPainter>
#include <QElapsedTimer>
#include <QFileDialog>
#include <QOpenGLWidget>
#include <QButtonGroup>
#include <QOpenGLFunctions>
#include <QStyleFactory>

#include <algorithm>
#include <random>
#include <set>
#include <utility>
#include <cmath>

using namespace std;

#define MAXSHU 44
#define MXUAN 11
#define MAXJSH 19
#define MAXND 1000
#define GQS 10
#define DBS 0.45
#define MANG 9
#define MAXGQS 60
#define MMN 12
#define MMM 22
#define MSI 55
#define eps 1e-9
#define ZGQS MAXGQS+15
#ifdef Q_OS_MAC
#define ME 0
#else
#ifdef Q_OS_ANDROID
#define ME 0
#else
#define ME 24
#endif
#endif

#define GL48 5

struct Plant
{
    QColor color;//子弹颜色
    int attack;//攻击力
    int time;//攻击时间(毫秒)
    int dztm;//能量豆时间(毫秒)
    int move_spd;//移动速度(子弹)
    int life;//生命值
    int x,y;//位置
    int id;//图片id
    int cost;//阳光值
    int type;//唯一标记
    int siz;//子弹大小
    int fu;
    int num;//下标
    bool freeze;//是否寒冰
    bool mush;//蘑菇
    bool inst;//瞬时
    int jian,fei;//溅射，化肥
    int tag,nxt_tm;//特殊变量，下次时间
    bool left;
    Plant(){nxt_tm=-1;left=0;}
    void Create(QColor Color,int Goj,int Time,int Dztm,int Sd,int Shm,int X,int Y,int Id,int Yg,int Lx,int Dx=10,bool Hb=false,bool Mg=false,bool Zha=false)
    {
        color=Color;
        attack=Goj;
        time=Time;
        dztm=Dztm;
        move_spd=Sd;
        life=Shm;
        x=X;
        y=Y;
        id=Id;
        cost=Yg;
        type=Lx;
        siz=Dx;
        freeze=Hb;
        mush=Mg;
        fu=0;
        if(Zha)
            fu=Dx;
        inst=Zha;
        tag=jian=fei=0;nxt_tm=-1;
        if(type==30)tag=9;//炮
    }
    void input(QDataStream &ar)
    {
        ar>>color>>attack;
        ar>>time>>dztm;
        ar>>move_spd>>life;
        ar>>x>>y>>id;
        ar>>cost>>type;
        ar>>siz>>fu;
        ar>>freeze>>mush;
        ar>>inst>>tag>>nxt_tm;
        ar>>jian>>fei>>left;
    }
    void output(QDataStream &ar)
    {
        ar<<color<<attack;
        ar<<time<<dztm;
        ar<<move_spd<<life;
        ar<<x<<y<<id;
        ar<<cost<<type;
        ar<<siz<<fu;
        ar<<freeze<<mush;
        ar<<inst<<tag<<nxt_tm;
        ar<<jian<<fei<<left;
    }
};
struct Zombie
{
    int life;//生命值
    int spd;//移动速度
    int eat;//吃速度
    int x,y;//位置
    int id;//图片id
    int type;//编号
    bool jump;//是否跳
    int freeze;//寒冰
    bool fu;
    bool shoot;//是否发射
    int fss;//发射延迟
    int num;//下标
    bool eating,fei;//正在吃，化肥有无
    void Create(int Sd,int Shm,int Eat,int X,int Y,int Id,int Lx,bool Beat=false,bool Fs=false)
    {
        spd=Sd;
        life=Shm;
        x=X;
        y=Y;
        id=Id;
        eat=Eat;
        type=Lx;
        jump=Beat;
        freeze=100;
        fu=false;
        shoot=Fs;
        fss=0;
        eating=false;
        fei=false;
    }
    void input(QDataStream &ar)
    {
        ar>>life>>spd>>eat;
        ar>>x>>y>>id;
        ar>>type>>jump>>freeze;
        ar>>fu>>shoot>>fss>>fei;
    }
    void output(QDataStream &ar)
    {
        ar<<life<<spd<<eat;
        ar<<x<<y<<id;
        ar<<type<<jump<<freeze;
        ar<<fu<<shoot<<fss<<fei;
    }
};
struct Bullet
{
    QColor color;//子弹颜色
    int spd;//移动速度
    int x,y;//位置
    int attack;//攻击力
    int siz;//大小
    bool freeze,tes,mh;//寒冰，五角星检测，魅惑
    int sx,tx,zx,zy,jian;//起点，终点，溅射范围
    bool left;
    Bullet(){tes=mh=freeze=false;jian=left=0;}
    void input(QDataStream &ar)
    {
        ar>>color>>spd;
        ar>>x>>y>>attack;
        ar>>siz>>freeze;
        ar>>sx>>tx>>zx>>zy;
        ar>>mh>>jian>>left;
    }
    void output(QDataStream &ar)
    {
        ar<<color<<spd;
        ar<<x<<y<<attack;
        ar<<siz<<freeze;
        ar<<sx<<tx<<zx<<zy;
        ar<<mh<<jian<<left;
    }
};

struct MyTimer
{
    int id,nxt,time;double extra;
    MyTimer(){}
    MyTimer(int Id,int Ne,int Jg,double Yu)
    {
        id=Id;nxt=Ne;time=Jg;extra=Yu;
    }
    void input(QDataStream &ar)
    {
        ar>>id>>nxt>>time;
    }
    void output(QDataStream &ar)
    {
        ar<<id<<nxt<<time;
    }
};
struct ARC
{
    int a,b,c;ARC(){}
    ARC(int A,int B,int C):a(A),b(B),c(C){}
};
bool operator<(const ARC&a,const ARC&b);

class CGame;
class MainWindow;

int GetZwIcon(Plant &zw);
int GetJsIcon(Zombie &js,CGame &ga);
int GetJsEat(Plant &zw,Zombie &js,CGame &ga);
void Fash(Zombie &js,CGame &ga);
bool DaZhao(Plant &zw,MainWindow* wnd);
void QxDaZhao(Plant &zw,MainWindow* wnd);
int MyRand(int cnt[100],int p[100],int n);

extern int XUAN,TM,MM,MN,SI;


#endif // STDAFX_H
